import commonIcon from './icon'
export const initPublicConfig = (theme) => {
  const {
    tooltipTextColor,
    tooltipBackgroundColor,
    tooltipAxisPointerTextColor,
    tooltipAxisPointerBackgroundColor,
    legendTextColor,
    legendPageTextColor,
    legendPageIconColor,
    legendPageIconInactiveColor
  } = theme
  return {
    tooltip: {
      trigger: 'axis',
      confine: true,
      enterable: true,
      extraCssText: 'max-height:100%; overflow-y:auto',
      textStyle: {
        color: tooltipTextColor
      },
      backgroundColor: tooltipBackgroundColor,
      axisPointer: {
        type: 'cross',
        label: {
          color: tooltipAxisPointerTextColor,
          backgroundColor: tooltipAxisPointerBackgroundColor,
          formatter: (params) => {
            const { value } = params
            return /^[+-]?\d*\.\d*$/.test(value) ? Number(value).toFixed(2) : value
          }
        }
      }
    },
    legend: {
      type: 'scroll',
      textStyle: {
        color: legendTextColor
      },
      itemWidth: 10,
      itemHeight: 10,
      padding: 0,
      icon: commonIcon.rect,
      pageTextStyle: {
        color: legendPageTextColor
      },
      pageIconColor: legendPageIconColor,
      pageIconInactiveColor: legendPageIconInactiveColor
    }
  }
}
